package homework;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-12-06
 * Time：14:43
 */
class Message {
    public String aa;
    public String bb;
}
@WebServlet("/message")
public class GetAndPostString extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        String a = req.getParameter("aa");
        String b = req.getParameter("bb");
        resp.getWriter().write(a + " " +b);
    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        resp.setContentType("text/html;charset=utf-8");
//        String a = req.getParameter("aa");
//        String b = req.getParameter("bb");
//        resp.getWriter().write(a + " " +b);
        ObjectMapper mapper = new ObjectMapper();
        Message message = mapper.readValue(req.getInputStream(), Message.class);
        resp.getWriter().write(message.aa + " " + message.bb);
    }
}
